﻿namespace MobileTrack.Web.Tests
{
    using System.Web.Security;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using MobileTrack.Core;
    using Moq;

    [TestClass]
    public class ExtensionsFixture
    {
        [TestMethod]
        public void ShouldGetRoleForUser()
        {
            var userName = "User1";
            var sucursal = "Sucursal1";
            var userRole = Constants.AdministradorRole;
            var sucursalRole = string.Concat(sucursal, Constants.SucursalRoleSuffix);

            var roleProviderMock = new Mock<RoleProvider>(MockBehavior.Strict);
            roleProviderMock.Setup(r => r.GetRolesForUser(userName)).Returns(new[] { userRole, sucursalRole });

            var result = Extensions.GetRoleForUser(roleProviderMock.Object, userName);

            Assert.AreEqual(userRole, result);

            roleProviderMock.VerifyAll();
        }

        [TestMethod]
        public void ShouldGetSucursalRoleForUser()
        {
            var userName = "User1";
            var sucursal = "Sucursal1";
            var userRole = Constants.AdministradorRole;
            var sucursalRole = string.Concat(sucursal, Constants.SucursalRoleSuffix);

            var roleProviderMock = new Mock<RoleProvider>(MockBehavior.Strict);
            roleProviderMock.Setup(r => r.GetRolesForUser(userName)).Returns(new[] { userRole, sucursalRole });

            var result = Extensions.GetSucursalRoleForUser(roleProviderMock.Object, userName);

            Assert.AreEqual(sucursal, result);

            roleProviderMock.VerifyAll();
        }
    }
}
